/**
 * 
 */
package com.thor.palmmall.rest.device.weibao.converter;

import java.util.ArrayList;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.KV;
import com.thor.commons.entity.UCN;
import com.thor.commons.util.ConverterUtil;
import com.thor.palmmall.rest.common.SAttachmentConverter;
import com.thor.palmmall.rest.common.SDeviceRepairMaterialConverter;
import com.thor.palmmall.rest.device.weibao.ADeviceWeibao4Create;
import com.thor.palmmall.spi.device.weibao.SDeviceWeibao4Create;

/**
 * @author NuoSa
 *
 * @since 1.0
 */
public class SDeviceWeibao4CreateConverter
    implements Converter<ADeviceWeibao4Create, SDeviceWeibao4Create> {

  public static SDeviceWeibao4CreateConverter getInstance() {
    if (instance == null)
      instance = new SDeviceWeibao4CreateConverter();
    return instance;
  }

  private static SDeviceWeibao4CreateConverter instance;

  private SDeviceWeibao4CreateConverter() {
  }

  @Override
  public SDeviceWeibao4Create convert(ADeviceWeibao4Create source) {
    if (source == null) {
      return null;
    }
    SDeviceWeibao4Create target = new SDeviceWeibao4Create();

    target.setPermGroupId(source.getPermGroupId());
    target.setPermGroupTitle(source.getPermGroupTitle());
    target.setStore(UCN.newInstance(source.getStore()));
    target.setTaskName(source.getTaskName());
    target.setCategory(UCN.newInstance(source.getCategory()));
    target.setMaintainer(UCN.newInstance(source.getMaintainer()));
    target.setSupervisor(UCN.newInstance(source.getSupervisor()));
    target.setDevice(UCN.newInstance(source.getDevice()));
    target.setAttachments(
        ConverterUtil.convert(source.getAttachments(), SAttachmentConverter.getInstance()));
    target.setItems(new ArrayList<KV>());
    target.getItems().addAll(source.getItems());
    target.setArtificialFee(source.getArtificialFee());
    target.setPartsFee(source.getPartsFee());
    target.setTotalFee(source.getTotalFee());
    target.setPosition(source.getPosition());
    target.setMaterials(
        ConverterUtil.convert(source.getMaterials(), SDeviceRepairMaterialConverter.getInstance()));

    target.setRemark(source.getRemark());

    return target;
  }

}
